package com.ssy.bus.controller;

import com.ssy.bus.pojo.Case;
import com.ssy.bus.service.ICaseService;
import com.ssy.common.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ssy
 */
@RestController
@RequestMapping("/case")
public class CaseController {

    @Autowired
    private ICaseService caseService;

    /**
     * 添加病例
     *
     * @param cases 病例数据
     * @return 病例表ID
     */
    @PostMapping("/addCase")
    public Result addCase(Case cases) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        cases.setId("BL" + sdf.format(date).substring(2));
        cases.setIsGrantDrug(2);
        return this.caseService.insertCase(cases);
    }

    /**
     * 修改挂号单的状态
     *
     * @param outpatientId 挂号ID
     * @return data
     */
    @PostMapping("/updateOutpatientState/{outpatientId}")
    public Result updateOutpatientState(@PathVariable String outpatientId) {
        return this.caseService.updateOutpatientState(outpatientId);
    }

    /**
     * 加载患者病例信息
     *
     * @param outpatientId 挂号单ID
     * @return data
     */
    @GetMapping("/loadCaseInfo/{outpatientId}")
    public Result loadCaseInfo(@PathVariable String outpatientId) {
        return this.caseService.selectCaseByOutpatientId(outpatientId);
    }

}
